package kz.pompei.ifacer.conf;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Random;

import kz.pompei.ifacer.util.Util;

import org.junit.Test;

public class ConfigTest {
  private final Random rnd = new Random();
  
  @Test
  public void using() throws Exception {
    File confFile = new File("/tmp/conf" + rnd.nextInt() + ".txt");
    {
      PrintStream out = new PrintStream(confFile, "UTF-8");
      out.println("   #frgdsgfhshjg g jhgf jhg  fdsg rfwger");
      out.println();
      out.println("    asd = hello world   ");
      out.println("  dsa11 = pumkin");
      out.println("  dsa12 = hello");
      out.println();
      out.close();
    }
    Config conf = new Config(confFile);
    assertEquals("hello world", conf.get("asd"));
    assertEquals("pumkin", conf.get("dsa11"));
    
    conf.set("asd", "good by");
    conf.set("wow", "Shyrli-myrli");
    conf.remove("dsa12");
    
    conf.write();
    
    Util.copy(new FileInputStream(confFile), System.out);
    System.out.println("FINISH");
  }
}
